package models;

import helpers.StringHelpers;
import play.db.jpa.GenericModel;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Users")
public class User extends GenericModel {
    public static final User Unknown = new User("", "", "");

    @Id
    @Column(name = "login", length = 20)
    public String login;

    @Column(name = "name", length = 50)
    public String name;

    @Column(name = "passwordHash")
    public int passwordHash;

    public User() {
    }

    public User(String login, String name, String password) {
        this.login = login;
        this.name = name;
        this.passwordHash = StringHelpers.getHash(password);
    }

    public User(String login, String name, int hash) {
        this.login = login;
        this.name = name;
        this.passwordHash = hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof User))
            return false;

        User _user = (User) obj;
        return this.login.equals(_user.login) && (this.passwordHash == _user.passwordHash);
    }

    public String getLogin() {
        return login;
    }

    public String getName() {
        return name;
    }

    public int getPasswordHash() {
        return passwordHash;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPasswordHash(int passwordHash) {
        this.passwordHash = passwordHash;
    }
}
